#include <string>
using namespace std;

string toHex(int num)
{
    string hex = "123456789abcdef";
    string res = "";
    if (num == 0)
        return "0";
    while (num && res.size() < 8)
    {
        res = hex[num & 0xf] + res;
        num >>= 4;
    }
    return res;
}